﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SuperSurvey.BUS;
using SuperSurvey.Entity;
namespace SuperSurvey
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ddlCountry.DataSource = RegisterBus.CountryList();
            ddlCountry.DataBind();
            ddlCountry.SelectedValue = "Vietnam";
        }

        protected void btnCalendar_Click(object sender, ImageClickEventArgs e)
        {
            calBirthDate.Visible = true;
        }

        protected void btnCreateAcc_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;
            string fullname = txtLastName.Text + " " + txtFirstName.Text;
            DateTime birthdate = Convert.ToDateTime(txtBirthDate.Text);
            string phone = txtPhone.Text;
            string email = txtEmail.Text;
            string address = txtAddress.Text;
            string country = ddlCountry.SelectedItem.ToString();

            UserLogin ul = new UserLogin
            {
                UserName = username,
                Password = password
            };
            UserInformation uf = new UserInformation
            {
                UserName = username,
                FullName = fullname,
                BirthDate = birthdate,
                Phone = phone,
                Email = email,
                Address = address,
                Country = country
            };            
            bool b = RegisterBus.InsertAccount(ul, uf);
            if (b)
            {
                Response.Write("<script>alert('" + "Create Success....." + "')</script>");
            }
            else
            {
                Response.Write("<script>alert('" + "Error....!!!" + "')</script>");
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtFirstName.Text = "";
            txtLastName.Text = "";
            txtPassword.Text = "";
            txtComfirmPassword.Text = "";
            txtBirthDate.Text = "";
            txtPhone.Text = "";
            txtEmail.Text = "";
            txtAddress.Text = "";
            ddlCountry.SelectedValue = "Vietnam";
        }

    }
}